from datetime import *
import os
import time as T
import pyautogui as P

tmNow = datetime.now()
d = date.today()


L=[]
with open('../off.txt','r')as F:
     for i in F:
          L.append(int(i))
     print(f'当前设定的时间为{L[0]}:{L[1]}:{L[2]}和{L[3]}:{L[4]}:{L[5]}')
     t1 = time(L[0],L[1],L[2])
     #t1 = time(int(input('h')),int(input('m')),int(input('s')))#
     t2 = time(L[3],L[4],L[5])
     #t2 = time(int(input('h')),int(input('m')),int(input('s')))#

shtdownTime1 = datetime.combine(d,t1)
shtdownTime2 = datetime.combine(d,t2)

def ShutDown(T):
     tmNow = datetime.now()
     timedDelta = (T - tmNow).total_seconds()
     if timedDelta < -5:
          print('过时')
          return ('continue')
     if timedDelta < 57and timedDelta > -3:
          os.system('shutdown -s -f -c 请及时在弹出的页面内选择 -t 80')
          print('到时')
          return ('break')
     else:
          print('没到')
          return ('continue')
          
            
if __name__ == '__main__':
     T.sleep(2)
     while True:
          if ShutDown(shtdownTime1)=='break' or ShutDown(shtdownTime2)=='break':
               T.sleep(2)
               break
          else:
               T.sleep(2)
               continue
     while True:
          P.hotkey('win', 'm')
          #userword=P.confirm(text='请选择关机时间:\n(1分钟未选择自动关机)',title='温馨提示',buttons=['3分钟后','6分钟后','重启','注销','关机'])
          userword=P.confirm(text='请选择关机时间:\n(1分钟未选择自动关机)',title='温馨提示',buttons=['3分钟后','6分钟后','关机'])
          if userword=='3分钟后':
               os.system('shutdown -a')
               for i in range(180,0,-1):
                    T.sleep(1)
                    print(i)
               os.system('shutdown -s -f -t 80')
          elif userword=='6分钟后':
               os.system('shutdown -a')
               for i in range(360,0,-1):
                    T.sleep(1)
                    print(i)
               os.system('shutdown -s -f -t 80')
          elif userword=='关机':
               os.system('shutdown -a')
               os.system('shutdown -s -f -t 1')
               break
          elif userword=='注销':
               os.system('shutdown -a')
               os.system('shutdown -l -f -t 1')#L
               break
          elif userword=='重启':
               os.system('shutdown -a')
               os.system('shutdown -r -f -t 1')#R
               break
